Page({

  /**
   * 页面的初始数据
   */
  data: {
    wechat: [
      { id: "1", name: "微信", checked: 'checked' },
      { id: "2", name: '手机' },
    ],
    manandgril: [
      { id: "1", name: "男士", checked: 'checked' },
      { id: "2", name: '女士' },
    ],
    problem_mode: [
      { id: "1", name: "技术问题", checked: 'checked' },
      { id: "2", name: '内容问题' },
    ],
    problem: 1,
    sex: 1,
    tel: 1,
  },
  // 问题分类
  problem: function (e) {
    var id = e.detail.value;
    var pos = this.data.problem_mode;
    for (var index in pos) {
      if (pos[index].id == id) {
        pos[index].checked = 'checked';
      } else {
        pos[index].checked = '';
      }
    }
    this.setData({
      problem_mode: pos,
      problem: id,
    })
  },
  manandgrilchoose: function (e) {
    //男女选择
    var id = e.detail.value;
    var pos = this.data.manandgril;
    for (var index in pos) {
      if (pos[index].id == id) {
        pos[index].checked = 'checked';
      } else {
        pos[index].checked = '';
      }
    }
    this.setData({
      manandgril: pos,
      sex:id,
    })
  },
  wechatchoose: function (e) {
    //联系方式选择
    var id = e.detail.value;
    var pos = this.data.wechat;
    for (var index in pos) {
      if (pos[index].id == id) {
        pos[index].checked = 'checked';
      } else {
        pos[index].checked = '';
      }
    }
    this.setData({
      wechat: pos,
      tel:id,
    })
  },
  /**
   * 表单提交
   */
  formSubmit: function (e) {
    var e = e.detail.value;
    var tel = this.data.tel;
    var sex = this.data.sex;
    var problem = this.data.problem;
    console.log(e);
    wx.request({
      url: getApp().AppUrl + '/index.php/api/set/saveOpinion',
      data: {
        name: e.name,
        content: e.content,
        tel: e.tels,
        ts: tel,
        sex: sex,
        problem: problem
      },
      success: function (res) {
        if (res.data == 1) {
          wx.showToast({
            title: '提交成功',
            icon: 'success',
            duration: 2000
          })
          setTimeout(function () {
            wx.navigateBack({})
          }, 2000)
        } else {
          wx.showToast({
            title: '提交失败',
            icon: 'success',
            duration: 2000
          })
        }

      },
    })
  },
  locationlw: function () {
    wx.navigateBack({
    })
  },
  locationdesc: function () {
    wx.navigateTo({
      url: '../Description/Description'
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})